package com.ruoyi.project.system.user.controller;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.RandomUtil;
import com.ruoyi.Test.RandomValue;
import com.ruoyi.project.order.mapper.WorkOrderMapper;
import com.ruoyi.project.order.service.IWorkOrderService;
import com.ruoyi.project.order.vo.OrderListVo;
import com.ruoyi.project.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.system.config.service.IConfigService;
import com.ruoyi.project.system.menu.domain.Menu;
import com.ruoyi.project.system.menu.service.IMenuService;
import com.ruoyi.project.system.user.domain.User;

/**
 * 首页 业务处理
 *
 * @author ruoyi
 */
@Controller
public class IndexController extends BaseController {
    @Autowired
    private IMenuService menuService;

    @Autowired
    private IConfigService configService;

    @Autowired
    private RuoYiConfig ruoYiConfig;
    @Autowired
    WorkOrderMapper workOrderMapper;
    // 系统首页
    @GetMapping("/index")

    public String index(ModelMap mmap) {
        // 取身份信息
        User user = getSysUser();
        // 根据用户id取出菜单
        List<Menu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme"));
        mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName"));
        mmap.put("copyrightYear", ruoYiConfig.getCopyrightYear());
        mmap.put("demoEnabled", ruoYiConfig.isDemoEnabled());
        return "index";
    }

    // 切换主题
    @GetMapping("/system/switchSkin")
    public String switchSkin(ModelMap mmap) {
        return "skin";
    }


   // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap) {
        List<OrderListVo> orderListVos = workOrderMapper.LGetUserOrderNum();
        List<String> names = new ArrayList<>();
        List<Integer> orderNums = new ArrayList<>();
        for (OrderListVo orderListVo : orderListVos) {
            names.add(orderListVo.getWorker());
            orderNums.add(orderListVo.getOrderNum());
        }

        mmap.put("version", ruoYiConfig.getVersion());
        mmap.put("names", names);
        mmap.put("len", names.size());
        mmap.put("orderNums", orderNums);
        return "main";
    }
}
